{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   satisfaction_level  last_evaluation  number_project  average_montly_hours  \\\n",
      "0                0.38             0.53               2                   157   \n",
      "1                0.80             0.86               5                   262   \n",
      "2                0.11             0.88               7                   272   \n",
      "3                0.72             0.87               5                   223   \n",
      "4                0.37             0.52               2                   159   \n",
      "\n",
      "   time_spend_company  Work_accident  left  promotion_last_5years  sales  \\\n",
      "0                   3              0     1                      0  sales   \n",
      "1                   6              0     1                      0  sales   \n",
      "2                   4              0     1                      0  sales   \n",
      "3                   5              0     1                      0  sales   \n",
      "4                   3              0     1                      0  sales   \n",
      "\n",
      "   salary  \n",
      "0     low  \n",
      "1  medium  \n",
      "2  medium  \n",
      "3     low  \n",
      "4     low  \n",
      "Nulls in the data set satisfaction_level       0\n",
      "last_evaluation          0\n",
      "number_project           0\n",
      "average_montly_hours     0\n",
      "time_spend_company       0\n",
      "Work_accident            0\n",
      "left                     0\n",
      "promotion_last_5years    0\n",
      "sales                    0\n",
      "salary                   0\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "hr_data = pd.read_csv('data/hr.csv', header=0)\n",
    "print (hr_data.head())\n",
    "print('Nulls in the data set' ,hr_data.isnull().sum())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nulls in the data set satisfaction_level           0\n",
      "last_evaluation              0\n",
      "number_project            2388\n",
      "average_montly_hours        86\n",
      "time_spend_company           0\n",
      "Work_accident                0\n",
      "left                         0\n",
      "promotion_last_5years    14680\n",
      "sales                        0\n",
      "salary                       0\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "#As there are no null introduce some nulls by replacing o in promotion_last_5years with NaN\n",
    "hr_data[['promotion_last_5years']] = hr_data[[ 'promotion_last_5years']].replace(0, np.NaN)\n",
    "#As there are no null introduce some nulls by replacing 262 in promotion_last_5years with NaN\n",
    "hr_data[['average_montly_hours']] = hr_data[[ 'average_montly_hours']].replace(262, np.NaN)\n",
    "#Replace 2 in number_project with NaN\n",
    "hr_data[['number_project']] = hr_data[[ 'number_project']].replace(2, np.NaN)\n",
    "\n",
    "print('Nulls in the data set', hr_data.isnull().sum())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Shape of the data set before removing nulls  (14999, 10)\n",
      "Shape of the data set after removing nulls  (278, 10)\n"
     ]
    }
   ],
   "source": [
    "#Remove rows\n",
    "hr_data_1 = hr_data.copy()\n",
    "print('Shape of the data set before removing nulls ', hr_data_1.shape)\n",
    "# drop rows with missing values\n",
    "hr_data_1.dropna(inplace=True)\n",
    "# summarize the number of rows and columns in the dataset\n",
    "print('Shape of the data set after removing nulls ',hr_data_1.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "satisfaction_level       0\n",
      "last_evaluation          0\n",
      "number_project           0\n",
      "average_montly_hours     0\n",
      "time_spend_company       0\n",
      "Work_accident            0\n",
      "left                     0\n",
      "promotion_last_5years    0\n",
      "sales                    0\n",
      "salary                   0\n",
      "dtype: int64\n",
      "   satisfaction_level  last_evaluation  number_project  average_montly_hours  \\\n",
      "0                0.38             0.53          -999.0                 157.0   \n",
      "1                0.80             0.86             5.0                -999.0   \n",
      "2                0.11             0.88             7.0                 272.0   \n",
      "3                0.72             0.87             5.0                 223.0   \n",
      "4                0.37             0.52          -999.0                 159.0   \n",
      "\n",
      "   time_spend_company  Work_accident  left  promotion_last_5years  sales  \\\n",
      "0                   3              0     1                 -999.0  sales   \n",
      "1                   6              0     1                 -999.0  sales   \n",
      "2                   4              0     1                 -999.0  sales   \n",
      "3                   5              0     1                 -999.0  sales   \n",
      "4                   3              0     1                 -999.0  sales   \n",
      "\n",
      "   salary  \n",
      "0     low  \n",
      "1  medium  \n",
      "2  medium  \n",
      "3     low  \n",
      "4     low  \n"
     ]
    }
   ],
   "source": [
    "#Mark global constant for missing values\n",
    "hr_data_3 = hr_data.copy()\n",
    "# fill missing values with -999\n",
    "hr_data_3.fillna(-999, inplace=True)\n",
    "# count the number of NaN values in each column\n",
    "print(hr_data_3.isnull().sum())\n",
    "print(hr_data_3.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "satisfaction_level       0\n",
      "last_evaluation          0\n",
      "number_project           0\n",
      "average_montly_hours     0\n",
      "time_spend_company       0\n",
      "Work_accident            0\n",
      "left                     0\n",
      "promotion_last_5years    0\n",
      "sales                    0\n",
      "salary                   0\n",
      "dtype: int64\n",
      "   satisfaction_level  last_evaluation  number_project  average_montly_hours  \\\n",
      "0                0.38             0.53        4.144477            157.000000   \n",
      "1                0.80             0.86        5.000000            200.698853   \n",
      "2                0.11             0.88        7.000000            272.000000   \n",
      "3                0.72             0.87        5.000000            223.000000   \n",
      "4                0.37             0.52        4.144477            159.000000   \n",
      "\n",
      "   time_spend_company  Work_accident  left  promotion_last_5years  sales  \\\n",
      "0                   3              0     1                    1.0  sales   \n",
      "1                   6              0     1                    1.0  sales   \n",
      "2                   4              0     1                    1.0  sales   \n",
      "3                   5              0     1                    1.0  sales   \n",
      "4                   3              0     1                    1.0  sales   \n",
      "\n",
      "   salary  \n",
      "0     low  \n",
      "1  medium  \n",
      "2  medium  \n",
      "3     low  \n",
      "4     low  \n"
     ]
    }
   ],
   "source": [
    "#Replace mean for missing values\n",
    "hr_data_2 = hr_data.copy()\n",
    "# fill missing values with mean column values\n",
    "hr_data_2.fillna(hr_data_2.mean(), inplace=True)\n",
    "# count the number of NaN values in each column\n",
    "print(hr_data_2.isnull().sum())\n",
    "print(hr_data_2.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>satisfaction_level</th>\n",
       "      <th>last_evaluation</th>\n",
       "      <th>number_project</th>\n",
       "      <th>average_montly_hours</th>\n",
       "      <th>time_spend_company</th>\n",
       "      <th>Work_accident</th>\n",
       "      <th>left</th>\n",
       "      <th>promotion_last_5years</th>\n",
       "      <th>sales</th>\n",
       "      <th>salary</th>\n",
       "      <th>number_project_was_missing</th>\n",
       "      <th>average_montly_hours_was_missing</th>\n",
       "      <th>promotion_last_5years_was_missing</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.38</td>\n",
       "      <td>0.53</td>\n",
       "      <td>NaN</td>\n",
       "      <td>157.0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>sales</td>\n",
       "      <td>low</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.80</td>\n",
       "      <td>0.86</td>\n",
       "      <td>5.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>sales</td>\n",
       "      <td>medium</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.11</td>\n",
       "      <td>0.88</td>\n",
       "      <td>7.0</td>\n",
       "      <td>272.0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>sales</td>\n",
       "      <td>medium</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.72</td>\n",
       "      <td>0.87</td>\n",
       "      <td>5.0</td>\n",
       "      <td>223.0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>sales</td>\n",
       "      <td>low</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.37</td>\n",
       "      <td>0.52</td>\n",
       "      <td>NaN</td>\n",
       "      <td>159.0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>sales</td>\n",
       "      <td>low</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   satisfaction_level  last_evaluation  number_project  average_montly_hours  \\\n",
       "0                0.38             0.53             NaN                 157.0   \n",
       "1                0.80             0.86             5.0                   NaN   \n",
       "2                0.11             0.88             7.0                 272.0   \n",
       "3                0.72             0.87             5.0                 223.0   \n",
       "4                0.37             0.52             NaN                 159.0   \n",
       "\n",
       "   time_spend_company  Work_accident  left  promotion_last_5years  sales  \\\n",
       "0                   3              0     1                    NaN  sales   \n",
       "1                   6              0     1                    NaN  sales   \n",
       "2                   4              0     1                    NaN  sales   \n",
       "3                   5              0     1                    NaN  sales   \n",
       "4                   3              0     1                    NaN  sales   \n",
       "\n",
       "   salary number_project_was_missing average_montly_hours_was_missing  \\\n",
       "0     low                       True                            False   \n",
       "1  medium                      False                             True   \n",
       "2  medium                      False                            False   \n",
       "3     low                      False                            False   \n",
       "4     low                       True                            False   \n",
       "\n",
       "  promotion_last_5years_was_missing  \n",
       "0                              True  \n",
       "1                              True  \n",
       "2                              True  \n",
       "3                              True  \n",
       "4                              True  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# make copy to avoid changing original data (when Imputing)\n",
    "hr_data_4 = hr_data.copy()\n",
    "\n",
    "# make new columns indicating what is imputed\n",
    "cols_with_missing = (col for col in hr_data_4.columns \n",
    "                                 if hr_data_4[col].isnull().any())\n",
    "for col in cols_with_missing:\n",
    "    hr_data_4[col + '_was_missing'] = hr_data_4[col].isnull()\n",
    "    \n",
    "hr_data_4.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Imputing row 1/14999 with 2 missing, elapsed time: 46.560\n",
      "Imputing row 101/14999 with 2 missing, elapsed time: 46.574\n",
      "Imputing row 201/14999 with 1 missing, elapsed time: 46.586\n",
      "Imputing row 301/14999 with 2 missing, elapsed time: 46.599\n",
      "Imputing row 401/14999 with 1 missing, elapsed time: 46.611\n",
      "Imputing row 501/14999 with 1 missing, elapsed time: 46.622\n",
      "Imputing row 601/14999 with 1 missing, elapsed time: 46.635\n",
      "Imputing row 701/14999 with 2 missing, elapsed time: 46.647\n",
      "Imputing row 801/14999 with 1 missing, elapsed time: 46.660\n",
      "Imputing row 901/14999 with 1 missing, elapsed time: 46.677\n",
      "Imputing row 1001/14999 with 0 missing, elapsed time: 46.690\n",
      "Imputing row 1101/14999 with 2 missing, elapsed time: 46.702\n",
      "Imputing row 1201/14999 with 1 missing, elapsed time: 46.714\n",
      "Imputing row 1301/14999 with 1 missing, elapsed time: 46.733\n",
      "Imputing row 1401/14999 with 2 missing, elapsed time: 46.745\n",
      "Imputing row 1501/14999 with 1 missing, elapsed time: 46.758\n",
      "Imputing row 1601/14999 with 1 missing, elapsed time: 46.782\n",
      "Imputing row 1701/14999 with 2 missing, elapsed time: 46.800\n",
      "Imputing row 1801/14999 with 1 missing, elapsed time: 46.814\n",
      "Imputing row 1901/14999 with 1 missing, elapsed time: 46.842\n",
      "Imputing row 2001/14999 with 1 missing, elapsed time: 46.872\n",
      "Imputing row 2101/14999 with 1 missing, elapsed time: 46.903\n",
      "Imputing row 2201/14999 with 1 missing, elapsed time: 46.911\n",
      "Imputing row 2301/14999 with 1 missing, elapsed time: 46.928\n",
      "Imputing row 2401/14999 with 1 missing, elapsed time: 46.941\n",
      "Imputing row 2501/14999 with 1 missing, elapsed time: 46.950\n",
      "Imputing row 2601/14999 with 1 missing, elapsed time: 46.962\n",
      "Imputing row 2701/14999 with 1 missing, elapsed time: 46.970\n",
      "Imputing row 2801/14999 with 1 missing, elapsed time: 46.979\n",
      "Imputing row 2901/14999 with 1 missing, elapsed time: 46.988\n",
      "Imputing row 3001/14999 with 1 missing, elapsed time: 46.998\n",
      "Imputing row 3101/14999 with 1 missing, elapsed time: 47.014\n",
      "Imputing row 3201/14999 with 1 missing, elapsed time: 47.027\n",
      "Imputing row 3301/14999 with 1 missing, elapsed time: 47.035\n",
      "Imputing row 3401/14999 with 2 missing, elapsed time: 47.043\n",
      "Imputing row 3501/14999 with 1 missing, elapsed time: 47.050\n",
      "Imputing row 3601/14999 with 1 missing, elapsed time: 47.058\n",
      "Imputing row 3701/14999 with 1 missing, elapsed time: 47.066\n",
      "Imputing row 3801/14999 with 1 missing, elapsed time: 47.074\n",
      "Imputing row 3901/14999 with 1 missing, elapsed time: 47.087\n",
      "Imputing row 4001/14999 with 1 missing, elapsed time: 47.094\n",
      "Imputing row 4101/14999 with 1 missing, elapsed time: 47.102\n",
      "Imputing row 4201/14999 with 1 missing, elapsed time: 47.109\n",
      "Imputing row 4301/14999 with 1 missing, elapsed time: 47.117\n",
      "Imputing row 4401/14999 with 1 missing, elapsed time: 47.124\n",
      "Imputing row 4501/14999 with 0 missing, elapsed time: 47.131\n",
      "Imputing row 4601/14999 with 1 missing, elapsed time: 47.137\n",
      "Imputing row 4701/14999 with 1 missing, elapsed time: 47.145\n",
      "Imputing row 4801/14999 with 1 missing, elapsed time: 47.151\n",
      "Imputing row 4901/14999 with 1 missing, elapsed time: 47.159\n",
      "Imputing row 5001/14999 with 1 missing, elapsed time: 47.166\n",
      "Imputing row 5101/14999 with 1 missing, elapsed time: 47.173\n",
      "Imputing row 5201/14999 with 1 missing, elapsed time: 47.180\n",
      "Imputing row 5301/14999 with 2 missing, elapsed time: 47.187\n",
      "Imputing row 5401/14999 with 2 missing, elapsed time: 47.196\n",
      "Imputing row 5501/14999 with 1 missing, elapsed time: 47.205\n",
      "Imputing row 5601/14999 with 2 missing, elapsed time: 47.215\n",
      "Imputing row 5701/14999 with 1 missing, elapsed time: 47.233\n",
      "Imputing row 5801/14999 with 1 missing, elapsed time: 47.243\n",
      "Imputing row 5901/14999 with 1 missing, elapsed time: 47.253\n",
      "Imputing row 6001/14999 with 1 missing, elapsed time: 47.263\n",
      "Imputing row 6101/14999 with 1 missing, elapsed time: 47.275\n",
      "Imputing row 6201/14999 with 1 missing, elapsed time: 47.284\n",
      "Imputing row 6301/14999 with 1 missing, elapsed time: 47.292\n",
      "Imputing row 6401/14999 with 1 missing, elapsed time: 47.301\n",
      "Imputing row 6501/14999 with 1 missing, elapsed time: 47.310\n",
      "Imputing row 6601/14999 with 1 missing, elapsed time: 47.318\n",
      "Imputing row 6701/14999 with 1 missing, elapsed time: 47.327\n",
      "Imputing row 6801/14999 with 1 missing, elapsed time: 47.336\n",
      "Imputing row 6901/14999 with 1 missing, elapsed time: 47.344\n",
      "Imputing row 7001/14999 with 1 missing, elapsed time: 47.352\n",
      "Imputing row 7101/14999 with 1 missing, elapsed time: 47.360\n",
      "Imputing row 7201/14999 with 1 missing, elapsed time: 47.369\n",
      "Imputing row 7301/14999 with 1 missing, elapsed time: 47.378\n",
      "Imputing row 7401/14999 with 1 missing, elapsed time: 47.387\n",
      "Imputing row 7501/14999 with 1 missing, elapsed time: 47.395\n",
      "Imputing row 7601/14999 with 1 missing, elapsed time: 47.404\n",
      "Imputing row 7701/14999 with 1 missing, elapsed time: 47.416\n",
      "Imputing row 7801/14999 with 1 missing, elapsed time: 47.429\n",
      "Imputing row 7901/14999 with 1 missing, elapsed time: 47.437\n",
      "Imputing row 8001/14999 with 1 missing, elapsed time: 47.446\n",
      "Imputing row 8101/14999 with 1 missing, elapsed time: 47.456\n",
      "Imputing row 8201/14999 with 1 missing, elapsed time: 47.466\n",
      "Imputing row 8301/14999 with 2 missing, elapsed time: 47.476\n",
      "Imputing row 8401/14999 with 1 missing, elapsed time: 47.485\n",
      "Imputing row 8501/14999 with 1 missing, elapsed time: 47.494\n",
      "Imputing row 8601/14999 with 1 missing, elapsed time: 47.504\n",
      "Imputing row 8701/14999 with 1 missing, elapsed time: 47.513\n",
      "Imputing row 8801/14999 with 1 missing, elapsed time: 47.523\n",
      "Imputing row 8901/14999 with 1 missing, elapsed time: 47.532\n",
      "Imputing row 9001/14999 with 1 missing, elapsed time: 47.543\n",
      "Imputing row 9101/14999 with 1 missing, elapsed time: 47.554\n",
      "Imputing row 9201/14999 with 1 missing, elapsed time: 47.564\n",
      "Imputing row 9301/14999 with 1 missing, elapsed time: 47.575\n",
      "Imputing row 9401/14999 with 1 missing, elapsed time: 47.585\n",
      "Imputing row 9501/14999 with 1 missing, elapsed time: 47.595\n",
      "Imputing row 9601/14999 with 1 missing, elapsed time: 47.605\n",
      "Imputing row 9701/14999 with 1 missing, elapsed time: 47.615\n",
      "Imputing row 9801/14999 with 1 missing, elapsed time: 47.628\n",
      "Imputing row 9901/14999 with 1 missing, elapsed time: 47.638\n",
      "Imputing row 10001/14999 with 1 missing, elapsed time: 47.649\n",
      "Imputing row 10101/14999 with 2 missing, elapsed time: 47.660\n",
      "Imputing row 10201/14999 with 1 missing, elapsed time: 47.670\n",
      "Imputing row 10301/14999 with 1 missing, elapsed time: 47.680\n",
      "Imputing row 10401/14999 with 1 missing, elapsed time: 47.690\n",
      "Imputing row 10501/14999 with 1 missing, elapsed time: 47.700\n",
      "Imputing row 10601/14999 with 1 missing, elapsed time: 47.711\n",
      "Imputing row 10701/14999 with 1 missing, elapsed time: 47.721\n",
      "Imputing row 10801/14999 with 1 missing, elapsed time: 47.730\n",
      "Imputing row 10901/14999 with 1 missing, elapsed time: 47.738\n",
      "Imputing row 11001/14999 with 2 missing, elapsed time: 47.745\n",
      "Imputing row 11101/14999 with 1 missing, elapsed time: 47.753\n",
      "Imputing row 11201/14999 with 1 missing, elapsed time: 47.762\n",
      "Imputing row 11301/14999 with 1 missing, elapsed time: 47.770\n",
      "Imputing row 11401/14999 with 0 missing, elapsed time: 47.780\n",
      "Imputing row 11501/14999 with 2 missing, elapsed time: 47.798\n",
      "Imputing row 11601/14999 with 1 missing, elapsed time: 47.835\n",
      "Imputing row 11701/14999 with 1 missing, elapsed time: 47.868\n",
      "Imputing row 11801/14999 with 1 missing, elapsed time: 47.898\n",
      "Imputing row 11901/14999 with 2 missing, elapsed time: 47.931\n",
      "Imputing row 12001/14999 with 2 missing, elapsed time: 47.966\n",
      "Imputing row 12101/14999 with 2 missing, elapsed time: 48.008\n",
      "Imputing row 12201/14999 with 1 missing, elapsed time: 48.049\n",
      "Imputing row 12301/14999 with 2 missing, elapsed time: 48.087\n",
      "Imputing row 12401/14999 with 1 missing, elapsed time: 48.122\n",
      "Imputing row 12501/14999 with 1 missing, elapsed time: 48.186\n",
      "Imputing row 12601/14999 with 1 missing, elapsed time: 48.376\n",
      "Imputing row 12701/14999 with 2 missing, elapsed time: 48.630\n",
      "Imputing row 12801/14999 with 1 missing, elapsed time: 48.699\n",
      "Imputing row 12901/14999 with 1 missing, elapsed time: 48.728\n",
      "Imputing row 13001/14999 with 1 missing, elapsed time: 48.756\n",
      "Imputing row 13101/14999 with 1 missing, elapsed time: 48.790\n",
      "Imputing row 13201/14999 with 1 missing, elapsed time: 48.822\n",
      "Imputing row 13301/14999 with 1 missing, elapsed time: 48.879\n",
      "Imputing row 13401/14999 with 1 missing, elapsed time: 48.931\n",
      "Imputing row 13501/14999 with 1 missing, elapsed time: 48.984\n",
      "Imputing row 13601/14999 with 1 missing, elapsed time: 49.015\n",
      "Imputing row 13701/14999 with 1 missing, elapsed time: 49.043\n",
      "Imputing row 13801/14999 with 1 missing, elapsed time: 49.072\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Imputing row 13901/14999 with 1 missing, elapsed time: 49.110\n",
      "Imputing row 14001/14999 with 1 missing, elapsed time: 49.138\n",
      "Imputing row 14101/14999 with 0 missing, elapsed time: 49.188\n",
      "Imputing row 14201/14999 with 1 missing, elapsed time: 49.231\n",
      "Imputing row 14301/14999 with 1 missing, elapsed time: 49.286\n",
      "Imputing row 14401/14999 with 2 missing, elapsed time: 49.357\n",
      "Imputing row 14501/14999 with 2 missing, elapsed time: 49.448\n",
      "Imputing row 14601/14999 with 2 missing, elapsed time: 49.505\n",
      "Imputing row 14701/14999 with 1 missing, elapsed time: 49.560\n",
      "Imputing row 14801/14999 with 2 missing, elapsed time: 49.638\n",
      "Imputing row 14901/14999 with 2 missing, elapsed time: 49.691\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>satisfaction_level</th>\n",
       "      <th>last_evaluation</th>\n",
       "      <th>number_project</th>\n",
       "      <th>average_montly_hours</th>\n",
       "      <th>promotion_last_5years</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.38</td>\n",
       "      <td>0.53</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>157.000000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.80</td>\n",
       "      <td>0.86</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>215.666667</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.11</td>\n",
       "      <td>0.88</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>272.000000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.72</td>\n",
       "      <td>0.87</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>223.000000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.37</td>\n",
       "      <td>0.52</td>\n",
       "      <td>3.494849</td>\n",
       "      <td>159.000000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   satisfaction_level  last_evaluation  number_project  average_montly_hours  \\\n",
       "0                0.38             0.53        3.000000            157.000000   \n",
       "1                0.80             0.86        5.000000            215.666667   \n",
       "2                0.11             0.88        7.000000            272.000000   \n",
       "3                0.72             0.87        5.000000            223.000000   \n",
       "4                0.37             0.52        3.494849            159.000000   \n",
       "\n",
       "   promotion_last_5years  \n",
       "0                    1.0  \n",
       "1                    1.0  \n",
       "2                    1.0  \n",
       "3                    1.0  \n",
       "4                    1.0  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from fancyimpute import KNN\n",
    "\n",
    "hr_data_5 = hr_data.copy()\n",
    "hr_numeric = hr_data_5.select_dtypes(include=[np.float])\n",
    "hr_filled = pd.DataFrame(KNN(3).complete(hr_numeric))\n",
    "hr_filled.columns = hr_numeric.columns\n",
    "hr_filled.index = hr_numeric.index\n",
    "hr_filled.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
